package com.zhn;

import java.util.ArrayList;
import java.util.List;

public class Test1 {
    public static void main(String[] args) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        int[] arr = {1,4,5,6,5,8,6,7};
        extracted(arr);
        backTracking(arr,0,path,res);
        System.out.println(res);
    }

    private static void extracted(int[] arr) {
        for(int i = 0; i < arr.length; i++){
            for(int j = i+1; j < arr.length; j++){
                System.out.println(arr[i] +" "+ arr[j]);
            }
        }
    }

    public static void backTracking(int[] arr, int startIndex, List<Integer> path,List<List<Integer>> res){
        if(path.size() == 2){
            res.add(new ArrayList<>(path));
            return;
        }
        for(int i = startIndex; i < arr.length; i++){
            path.add(arr[i]);
            backTracking(arr,startIndex+1,path,res);
            path.remove(path.size() - 1);
        }
    }


}
